package cn.good.yan.model.service.impl;

//import cn.good.yan.config.demo2.DBUserDetailsManager;
import cn.good.yan.config.demo3.DBUserDetailsManager;
import cn.good.yan.model.entity.User;
import cn.good.yan.model.mapper.UserMapper;
import cn.good.yan.model.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Service;

/**
 * User 实体 Service层
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Resource
    private DBUserDetailsManager dbUserDetailsManager;

    @Override
    public void saveUserDetails(User user) {
        UserDetails userDetails = org.springframework.security.core.userdetails.User
                // 默认的加密规则，把用户名和密码，进行创建交给 security ，对密码进行加密，把加密后的密码，在传给Dao层，保存数据库中
                .withDefaultPasswordEncoder()
                .username(user.getUsername())  //自定义用户名
                .password(user.getPassword())  //自定义密码
                .build();
        dbUserDetailsManager.createUser(userDetails);
    }

}




